﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using DTO;
using System.Data.SqlClient;
using System.Windows;
namespace DA
{
    public class ThamSoDA : DBConnection
    {
        public ThamSoDA()
        {
            sqlCommand.Connection = sqlConnection;
        }

        public string GetThamSo(string _TenThamSo)
        {
            try
            {
                var ds = new DataSet();
                string query = string.Format("select * from THAMSO where tenthamso ='{0}'", _TenThamSo);
                if (open())
                {
                    sqlDataAdapter = new SqlDataAdapter(query, sqlConnection);
                    sqlDataAdapter.Fill(ds);
                }
                close();
                string rs = ds.Tables[0].Rows[0].ItemArray[2].ToString().Trim();
                
                return rs;

            }
            catch (Exception)
            {
                return string.Empty;
            }

        }

        public bool SetThamSo(string _TenThamSo, string _Giatri)
        {
            string query = String.Format("update THAMSO set {0}='{1}'",_TenThamSo,_Giatri );
            sqlCommand.CommandText = query;
            try
            {
                open();
                sqlCommand.ExecuteNonQuery();
                close();
                return true;
            }
            catch (SqlException s)
            {
                Console.WriteLine(s.Message);
                return false;
            }
        }
    }
}
